package com.otv.privilegio.dao;

import java.util.List;

import com.otv.model.Privilegio;
import org.hibernate.SessionFactory;


/**
 * Class PrivilegioDAO.
 */
public class PrivilegioDAO implements IPrivilegioDAO {
	
	/** El/la session factory. */
	private SessionFactory sessionFactory;

	/**
	 * Get Hibernate Session Factory.
	 *
	 * @return SessionFactory - Hibernate Session Factory
	 */
	public SessionFactory getSessionFactory() {
		return sessionFactory;
	}

	/**
	 * Set Hibernate Session Factory.
	 *
	 * @param sessionFactory un(a) nuevo(a) session factory
	 */
	public void setSessionFactory(SessionFactory sessionFactory) {
        this.sessionFactory = sessionFactory;
    }

	


	@Override
	public void addPrivilegio (Privilegio privilegio) {
		getSessionFactory().getCurrentSession().save(privilegio);
	}


	@Override
	public void updatePrivilegio(Privilegio privilegio) {
		getSessionFactory().getCurrentSession().update(privilegio);
	}


	@Override
	public void deletePrivilegio(Privilegio privilegio) {
		getSessionFactory().getCurrentSession().delete(privilegio);
	}


	@Override
	public Privilegio getPrivilegioById(int id) {
		return (Privilegio) getSessionFactory().getCurrentSession().createQuery("from Privilegio where id=?").setParameter(0,id).list().get(0);
	}


	@Override
	public List<Privilegio> getPrivilegios() {
		return getSessionFactory().getCurrentSession().createQuery("from Privilegio").list();
	}

}
